
   /**
    *  This class is the main class of the "World of Zuul" application. 
    *  "World of Zuul" is a very simple, text based adventure game.  Users 
    *  can walk around some scenery. That's all. It should really be extended 
    *  to make it more interesting!
    * 
    *  To play this game, create an instance of this class and call the "play"
    *  method.
    * 
    *  This main class creates and initialises all the others: it creates all
    *  rooms, creates the parser and starts the game.  It also evaluates and
    *  executes the commands that the parser returns.
    * 
    * @author  Michael Kölling and David J. Barnes
    * @version 2016.02.29
    */
public class Game 
{
    private Parser parser;
    private Room currentRoom;
    private Food bag = null;
    private Food bag1 = null;
    private int reduce = 10;
    private int increase = 10;
    private Player player;
    private boolean y = false;
    public int strength = 100;
    /**
     * Create the game and initialise its internal map.
     */
    public Game() 
    {
        createRooms();
        parser = new Parser();
        player = new Player();
    }

    /**
     * Create all the rooms and link their exits together.
     */
    private void createRooms()
    {
        Room zhmen, yard, door, hall, lobby, stairs, livingroom, kitchen, toilet, garden, upstairs, rooftop, midao;
      
        // create the rooms
        zhmen = new Room("莫名其妙来到了一座古堡的正门前",new Food("钥匙",20));
        yard = new Room("来到正门，进入了古堡的院子，在草坪上摸索了一会儿，发现了隐隐约约在发光的东西，让我们来看看这是什么吧！",new Food("金钥匙",30));
        door = new Room("得到钥匙，来到大门前，门旁边有一个邮筒，打开它，看看里面是什么吧",new Food("古堡地图",100));
        hall = new Room("打开大门，进入大厅，却不慎中了机关，受伤了",new Food("碰到机关",-200));
        lobby = new Room("来到走廊。");
        stairs = new Room("来到楼梯，不小心摔了一跤",new Food("楼梯",-50));
        livingroom = new Room("来到客厅，看了会儿电视，吃了点东西",new Food("水果",200));
        kitchen = new Room("来到了厨房：看到了一些食材，确定有人在这儿生活，咦，有什么东西在动，去看看是什么？",new Food("碰到老鼠",-80));
        toilet = new Room("来到了厕所：发现厕所门打不开，但是在门口发现了一把钥匙",new Food("很多钥匙",100));
        garden = new Room("用其中一个钥匙打开了花园的门，看到许多的花草，但没想到其中有一种话有毒，你中毒了",new Food("奇异花",-500));
        upstairs = new Room("来到了楼上，看见一道铁门，用钥匙打开铁门，成功的到达了二楼的空间");
        rooftop = new Room("来到二楼的天台，环顾四周，你貌似发现了什么");
        midao = new Room("通过一番波折，你终于找到了这个隐藏的密道，通过密道，你成功逃离了古堡，恭喜你，通关成功！！！");
        
        zhmen.setExit("north", yard);
        yard.setExit("north",door);
        yard.setExit("south",zhmen);
        door.setExit("north",hall);
        door.setExit("south",yard);
        hall.setExit("north",lobby);
        hall.setExit("south",door);
        hall.setExit("east",livingroom);
        hall.setExit("west",stairs);
        hall.setExit("up",upstairs);
        hall.setExit("down",midao);
        lobby.setExit("south",hall);
        stairs.setExit("north",upstairs);
        stairs.setExit("east",hall);
        stairs.setExit("west",kitchen);
        livingroom.setExit("west",hall);
        livingroom.setExit("east",garden);
        kitchen.setExit("east",stairs);
        kitchen.setExit("north",toilet);
        toilet.setExit("south",kitchen);
        garden.setExit("west",livingroom);
        garden.setExit("south",yard);
        upstairs.setExit("east",rooftop);
        upstairs.setExit("south",stairs);
        rooftop.setExit("west",upstairs);
        rooftop.setExit("east",midao);
        currentRoom = zhmen;  // start game zhmen
    }
    
    /**
     *  Main play routine.  Loops until end of play.
     */
    public void play() 
    {            
        printWelcome();

        // Enter the main command loop.  Here we repeatedly read commands and
        // execute them until the game is over.
                
        boolean finished = false;
        while (! finished) {
            Command command = parser.getCommand();
            finished = processCommand(command);
        }
        System.out.println("感谢您的参与，下次再见！");
    }

    /**
     * Print out the opening message for the player.
     */
    private void printWelcome()
    {
       System.out.println();
       System.out.println("欢迎来到古堡探险!");
       System.out.println("古堡探险新世界, 令人难忘的一次惊魂探险.");
       System.out.println("如果你需要帮助，就请输入'Help',但请你不要频繁操作！！！");
       System.out.println();
       System.out.println("你 " + currentRoom.getDescription());
       currentRoom.printExits();
    }

    /**
     * Given a command, process (that is: execute) the command.
     * @param command The command to be processed.
     * @return true If the command ends the game, false otherwise.
     */
    private boolean processCommand(Command command) 
    {
        
        boolean wantToQuit = false;
        if(command.isUnknown()) {
            System.out.println("我不明白你的意思");
            return false;
        }

        Word commandWord = command.getCommandWord();
        switch(commandWord){
            case HELP:
                printHelp();
                break;
            case GO:
                goRoom(command);
                player.step();
                break;
            case QUIT:
                wantToQuit = quit(command);
                break;
            case LOOK:
                Food food = currentRoom.getFood();
                if(food != null){
                    System.out.println("房间里有"+food.getName());
                }else{
                    System.out.println("这个房间里什么都没有。");
                }
                break;
            case PICK:
                Food foodc = currentRoom.getFood();
                if(foodc.getName()=="钥匙"){
                     if(bag==null){
                         bag=foodc;
                         System.out.println("你得到了"+ foodc.getName());
                     }
                     else
                         System.out.println("你不需要这个东西");
                }
                else if(foodc.getName()=="金钥匙"){
                     if(bag1==null){
                         bag1=foodc;
                         System.out.println("你得到了"+ foodc.getName());
                     }
                     else
                         System.out.println("你不需要这个东西");
                }
                else if(foodc.getName()=="古堡地图"){
                     increase+=100;
                     reduce+=0;
                     System.out.println("你获得了100的经验值");
                }
                else if(foodc.getName()=="机关"){
                     increase+=0;
                     reduce+=200;
                     System.out.println("你减少了200的经验值");
                }
                else if(foodc.getName()=="楼梯"){
                     increase+=0;
                     reduce+=50;
                     System.out.println("你减少了50的经验值");
                }
                else if(foodc.getName()=="水果"){
                     increase+=200;
                     reduce+=0;
                     System.out.println("你增加了200的经验值");
                }
                else if(foodc.getName()=="老鼠"){
                     increase+=0;
                     reduce+=80;
                     System.out.println("你减少了80的经验值");
                }
                else if(foodc.getName()=="钥匙"){
                     increase+=100;
                     reduce+=0;
                     System.out.println("你获得了100的经验值");
                }
                else if(foodc.getName()=="奇异花"){
                     increase+=0;
                     reduce+=200;
                     System.out.println("你减少了200的经验值");
                }
                break;
                
        }
        
        return wantToQuit;
    }

    // implementations of user commands:

    /**
     * Print out some help information.
     * Here we print some stupid, cryptic message and a list of the 
     * command words.
     */
    private void printHelp() 
    {
        System.out.println("你想要场外援助？？？");
        System.out.println("再去古堡周围找找有什么东西");
        System.out.println("你有多少经验值？？？");
        System.out.println("   再动动脑筋");
        Word[] words = Word.values();
        for(int i=0;i<words.length;i++){
            System.out.print(words[i].getCommandWord()+" ");
            System.out.println();
        }
    }
    /** 
     * Try to go in one direction. If there is an exit, enter
     * the new room, otherwise print an error message.
     */
    private void goRoom(Command command) 
    {
        if(!command.hasSecondWord()) {
            // if there is no second word, we don't know where to go...
            System.out.println("去哪儿?");
            return;
        }

        String direction = command.getSecondWord();
        Room nextRoom = currentRoom.goNext(direction);

        if (nextRoom == null) {
            System.out.println("这里没有门!");
        }
        else {
            currentRoom = nextRoom;
            System.out.println("你 " + currentRoom.getDescription());
            currentRoom.printExits();
        }
    }

    private boolean quit(Command command) 
    {
        if(command.hasSecondWord()) {
            System.out.println("Quit what?");
            return false;
        }
        else {
            return true;  // signal that we want to quit
        }
    }
}
